home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / hotshot / stats.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. '''Statistics analyzer for HotShot.'''
  5. import profile
  6. import pstats
  7. import hotshot.log as hotshot
  8. from hotshot.log import ENTER, EXIT
  9.  
  10. def load(filename):
  11.     return StatsLoader(filename).load()
  12.  
  13.  
  14. class StatsLoader:
  15.     
  16.     def __init__(self, logfn):
  17.         self._logfn = logfn
  18.         self._code = { }
  19.         self._stack = []
  20.         self.pop_frame = self._stack.pop
  21.  
  22.     
  23.     def load(self):
  24.         p = Profile()
  25.         p.get_time = _brokentimer
  26.         log = hotshot.log.LogReader(self._logfn)
  27.         taccum = 0
  28.         for event in log:
  29.             (filename, lineno, funcname) = (what,)
  30.             tdelta = event
  31.             if tdelta > 0:
  32.                 taccum += tdelta
  33.             
  34.             if what == ENTER:
  35.                 frame = self.new_frame(filename, lineno, funcname)
  36.                 p.trace_dispatch_call(frame, taccum * 9.9999999999999995e-07)
  37.                 taccum = 0
  38.                 continue
  39.             if what == EXIT:
  40.                 frame = self.pop_frame()
  41.                 p.trace_dispatch_return(frame, taccum * 9.9999999999999995e-07)
  42.                 taccum = 0
  43.                 continue
  44.         
  45.         return pstats.Stats(p)
  46.  
  47.     
  48.     def new_frame(self, *args):
  49.         
  50.         try:
  51.             code = self._code[args]
  52.         except KeyError:
  53.             code = FakeCode(*args)
  54.             self._code[args] = code
  55.  
  56.         if self._stack:
  57.             back = self._stack[-1]
  58.         else:
  59.             back = None
  60.         frame = FakeFrame(code, back)
  61.         self._stack.append(frame)
  62.         return frame
  63.  
  64.  
  65.  
  66. class Profile(profile.Profile):
  67.     
  68.     def simulate_cmd_complete(self):
  69.         pass
  70.  
  71.  
  72.  
  73. class FakeCode:
  74.     
  75.     def __init__(self, filename, firstlineno, funcname):
  76.         self.co_filename = filename
  77.         self.co_firstlineno = firstlineno
  78.         self.co_name = self.__name__ = funcname
  79.  
  80.  
  81.  
  82. class FakeFrame:
  83.     
  84.     def __init__(self, code, back):
  85.         self.f_back = back
  86.         self.f_code = code
  87.  
  88.  
  89.  
  90. def _brokentimer():
  91.     raise RuntimeError, 'this timer should not be called'
  92.  
  93.